package cn.tedu.oa.procedure.controller;


import cn.tedu.oa.common.vo.JsonResult;
import cn.tedu.oa.procedure.entity.Procedure;
import cn.tedu.oa.procedure.service.ProcedureService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/procedure/")
public class ProcedureController {
    @Autowired
    private ProcedureService procedureService;

    @RequestMapping("procedure_ui")
    public String doProcedureUI() {
        return "procedure/procedure_ui";
    }

    @RequestMapping("processAudit_ui")
    public String doProcessAuditUI() {
        return "procedure/processAudit_ui";
    }

    @RequestMapping("procedure_edit")
    public String doProcedureEditUI() {
        return "procedure/procedure_edit";
    }

    /*显示数据列表*/
    @RequestMapping("get")
    @ResponseBody
    public JsonResult get(String criteria,Integer pageNo,Integer pageSize) {
        List<Procedure> list = procedureService.getProcedurePagerList(criteria, pageNo, pageSize);
        int rowCount = procedureService.getRowCount(criteria);
        JsonResult result = new JsonResult();
        result.setCount(rowCount);
        result.setData(list);
        return result;
    }

    /*根据id删除数据*/
    @RequestMapping("deleteByIds")
    @ResponseBody
    public JsonResult deleteByIds(Integer... ids) {
        procedureService.deleteByIds(ids);
        return new JsonResult("delete ok");
    }
    /*根据id审核*/
    @RequestMapping("updateByIds")
    @ResponseBody
    public JsonResult updateByIds(Integer... ids) {
        procedureService.updateByIds(ids);
        return new JsonResult("ok");
    }


    /*添加流程*/
    @RequestMapping("addProcedure")
    @ResponseBody
    public JsonResult addProcedure(Procedure procedure) {
        procedureService.add(procedure);
        return new JsonResult("添加成功");
    }

    /*修改流程*/
    @RequestMapping("updateProcedure")
    @ResponseBody
    public  JsonResult updateProcedure(Procedure procedure){
        procedureService.update(procedure);
        return new JsonResult("修改成功");
    }

    /*按照id查询用户*/
    @RequestMapping("getProcedureById")
    @ResponseBody
    public Procedure getProcedureById(Integer id) {
        return procedureService.getProcedureById(id);
    }



}
